package com.ape.controller;

import com.ape.bean.ResultData;
import com.ape.entity.dto.UserDto;
import com.ape.entity.req.UserReq;
import com.ape.entity.req.UserReqList;
import com.ape.redis.utils.RedisUtils;
import com.ape.service.UserService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

@RestController
@RequestMapping(value ="/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private RedisUtils redisUtils;
    @PostMapping
    public ResultData addUser(@RequestBody UserReq userReq){
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(userReq, userDto);
//        int i=1/0;
        return ResultData.ok( userService.addUser(userDto));
    }


    @DeleteMapping("/{id}")
    public ResultData deleteUser(@PathVariable("id") Integer id){
        return ResultData.ok(userService.deleteUser(id));
    }

    @PostMapping("/getPage")
    public ResultData getPage(@RequestBody UserReqList userReqList){
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(userReqList,userDto);
        return ResultData.ok(userService.getUserPages(userDto));
    }

    @GetMapping("redisTest")
    public ResultData testRedisTest(){
        redisUtils.set("name","性感大奶主播柳岩");
        return ResultData.ok(redisUtils.get("name"));
    }
}
